Repository navigation
fix: next function is not available for pre middlewares in mongoose 9 - #171
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR upgrades the mongoose-delete plugin to support Mongoose 9.x while maintaining backward compatibility with versions 5-8. The main change addresses Mongoose 9's removal of the next callback parameter from pre middlewares by conditionally checking if next is a function before calling it.
- Adds Mongoose 9.x to peer dependencies
- Updates dev dependency to Mongoose ^9.0.0
- Fixes
pre('save')middleware to work with both old and new Mongoose versions
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| package.json | Adds Mongoose 9.x to peer dependencies and updates dev dependency to ^9.0.0 |
| package-lock.json | Updates dependency tree with Mongoose 9.0.0 and its transitive dependencies (mongodb 7.0.0, kareem 3.0.0, etc.) |
| index.js | Adds conditional check for next function in pre('save') middleware to support Mongoose 9's removal of callback parameter, plus code formatting improvements |
Comments suppressed due to low confidence (3)
index.js:347
- This expression assigns variable conditions to itself.
callback = adjustCallbackForMongooseVersion(callback);
index.js:211
- This negation always evaluates to true.
schema.statics[method + 'Deleted'] = function () {
index.js:217
- This negation always evaluates to true.
};
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
@dsanel Can we review this PR please? it's necessary for mongoose 9 support |
Owner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When trying to upgrade Mongoose in our app to 9, we faced this error:
That's because Mongoose 9 no longer passes
nexttopremiddlewares; instead, you either throw an error or do nothing.This PR attempts to fix the error while still passing the tests.